package com.family.service.impl;

import com.family.mapper.GenerationMapper;
import com.family.mapper.NameMapper;
import com.family.model.Generation;
import com.family.model.Name;
import com.family.service.GenerationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
//import org.mybatis.spring.support.SqlSessionDaoSupport;
//通过自动注入进来
import java.util.List;

@Service("generationService")
public class GenerationServiceImpl /*extends SqlSessionDaoSupport*/ implements GenerationService {
    private NameMapper nameMapper;
    private GenerationMapper generationMapper;

    @SuppressWarnings("SpringJavaAutowiringInspection")
    @Autowired
    public void setNameMapper(NameMapper nameMapper) {
        this.nameMapper = nameMapper;
    }

    @SuppressWarnings("SpringJavaAutowiringInspection")
    @Autowired
    public void setGenerationMapper(GenerationMapper generationMapper) {
        this.generationMapper = generationMapper;
    }

    @Override
    public Generation addGeneration(Generation generation) {
        /*int id = */
        generationMapper.addGeneration(generation);
//        generation.setId(id);
        return generation;
    }

    @Override
    public Generation queryGenerationByName(int nameId, String gValue) {
        Generation generation = new Generation();
        generation.setValue(gValue);
        Name name = new Name();
        name.setId(nameId);
        generation.setName(name);
        return generationMapper.queryGenerationByName(generation);
    }

    @Override
    public Generation queryGenerationById(int generationId) {
        return generationMapper.queryGenerationById(generationId);
    }

    @Override
    public List<Generation> queryGenerationsByNameId(int nameId) {
        return generationMapper.queryGenerationsByNameId(nameId);
    }

    @Override
    public List<Generation> queryGenerationsByParentId(int parentGenerationId) {
        return generationMapper.queryGenerationsByParentId(parentGenerationId);
    }

    @Override
    public void updateGenerations(List<Generation> generations) {
        generationMapper.updateGenerations(generations);
    }

    @Override
    public void deleteGenerationById(int generationId) {
        generationMapper.deleteGenerationById(generationId);
    }
}
